package critters;

import info.gridworld.actor.Actor;
import info.gridworld.actor.Critter;
import info.gridworld.actor.Flower;
import info.gridworld.actor.Rock;
import info.gridworld.grid.Location;

import java.util.ArrayList;

import java.util.ArrayList;

public class BlusterCritter extends Critter {

	private int courage;
	
	public BlusterCritter(int c)
	{
		courage = c;
	}
	
	public ArrayList<Actor> getActors()
    {
        ArrayList<Actor> actors = new ArrayList<Actor>();
        
        for (Location loc : getTwFoLocations())
        {
            Actor a = getGrid().get(loc);
            if (a != null)
                actors.add(a);
        }

        return actors;
    }
	
	
	public void processActors(ArrayList<Actor> actors)
	{
		int num=0;
		for(Actor a : actors)
		{
			if( !(a instanceof Rock) && !(a instanceof Critter))
				a.removeSelfFromGrid();
			else if( a instanceof Critter){
				num++;
			}
		}
		if( num > courage )
			setColor(getColor().darker());
		if( num <= courage )
			setColor(getColor().brighter());
	}
	
	
	
	public ArrayList<Location> getTwFoLocations()
	{
		ArrayList<Location> locs = new ArrayList<Location>();
		Location locTemp;
		Location loc = getLocation();
		int centerRow = loc.getRow();
		int centerCol = loc.getCol();
		for(int i = centerRow-2; i < centerRow+3; i++)
		{
			for(int j = centerCol-2; j < centerCol+3; j++)
			{
				locTemp = new Location(i,j);
				if(getGrid().isValid(locTemp))
					locs.add(locTemp);
			}
		}
		return locs;
	}
}
